/*
 * This is the listener for the connect button
 */
package gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import javax.swing.JButton;
import javax.swing.JTextField;

/**
 * @author Nana
 */
public class ConnectListener implements ActionListener {

    private JTextField txtfield;
    private ChatGUI gui;
    private JButton connect;
    private JButton disconnect;
    private JButton send;
    private JButton chooseFile;
    private BufferedImage bImgConnectOff;

    /**
     * The constructor of the listener
     *
     * @param txtfield The field with the usernae
     * @param gui The GUI
     * @param connect The connect button
     * @param disconnect The disconnect button
     * @param send The send buton
     * @param chooseFile The choose file button
     */
    public ConnectListener(JTextField txtfield, ChatGUI gui, JButton connect, JButton disconnect, JButton send, JButton chooseFile) {
        this.txtfield = txtfield;
        this.gui = gui;
        this.disconnect = disconnect;
        this.send = send;
        this.chooseFile = chooseFile;
        this.connect = connect;
    }

    /**
     * The action to perform when clicking on the connect button
     *
     * @param e The action event
     */
    @Override
    public void actionPerformed(ActionEvent e) {
        String username = txtfield.getText();
        txtfield.setEnabled(false);
        disconnect.setEnabled(true);
        send.setEnabled(true);
        chooseFile.setEnabled(true);
        connect.setEnabled(false);
        gui.Connect(username);
        System.out.println("Welcome in the chat, " + txtfield.getText() + " :)");
    }
}
